package com.example.testsqlite;

import java.util.List;
import android.app.Activity;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;

public class ShowContent extends Activity {
	
	public static final String CONTENT_REQUEST = "10";
	ListView listTable;
	String[] tableName;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show_content);

		listTable = (ListView) findViewById(R.id.listView_table);
		List<String> tableAndAttributeList = CreateTable.tableAndAttributeList;
		int num = tableAndAttributeList.size();
		Log.i("gjf", "num  "+num);
		tableName = new String[num / 4];
		for (int i = 0,j = 0; i < num; i++) {
			Log.i("gjf", "for (int i = 0,j = 0; i < num; i++) { ");
			if((i%4) == 0){
				Log.i("gjf", "if((i%4) == 0) ");
				tableName[j] = tableAndAttributeList.get(i).toString();
				Log.i("gjf", "tableName[j] = tableAndAttributeList.get(i).toString(); "+tableName[j]);
				j++;
			}			
		}
		
	    listTable.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tableName));
	    
	    listTable.setOnItemClickListener(onItemClickListener);
		
	}
	private OnItemClickListener onItemClickListener= new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			Bundle bundle = new Bundle();
			bundle.putString("table", tableName[arg2]);
			//bundle.putInt(CONTENT_REQUEST, arg2);	
			AttributeFragmnet attributeFragmnet = new AttributeFragmnet();
			attributeFragmnet.setArguments(bundle);			
	        getFragmentManager().beginTransaction().replace(R.id.frameLayout_attribute, attributeFragmnet).commit();		
		}		
	};
	
}
